package strangeattractor.UI;

import java.awt.*;

import javax.swing.JComponent;

import strangeattractor.core.*;
import strangeattractor.equations.*;

public class ImageRenderer extends JComponent implements Renderer {
	//ImageRenderer is the default method of displaying an image through a
	//graphical component.

	Image image = null;
	Generator gen = null;

	Transformer equation = null;

	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);

		if (image != null) {
			g2.drawImage(image, 0, 0, this);
		}
	}

	public ImageRenderer(Dimension size, Transformer equation) {
		StandardOrthographicProjector projector = new StandardOrthographicProjector(
				size.width, size.height);
		this.equation = equation;
		// this.setSize(size);
		gen = new Generator(projector, equation, new PreviewDotScheme(), this);
	}

	public ImageRenderer(Dimension size, Transformer equation, Renderer other) {
		StandardOrthographicProjector projector = new StandardOrthographicProjector(
				size.width, size.height);
		this.equation = equation;
		this.setSize(size);
		gen = new Generator(projector, equation, new PreviewDotScheme(), this,
				other);
	}

	public void render(Dimension size, int quality, int points) {
		gen.render(size.width, size.height, quality, points,
				new DefaultExposureScheme(gen.getCamera(), 100, 0.5,
						size.width, size.height));
	}

	public void render(Dimension size, int quality, int points, int exposure,
			double gamma) {
		gen.render(size.width, size.height, quality, points,
				new DefaultExposureScheme(gen.getCamera(), exposure, gamma,
						size.width, size.height));
	}

	public void render(Dimension size) {
		gen.render(size.width, size.height, 20000000, 1,
				new DefaultExposureScheme(gen.getCamera(), 100, 0.5,
						size.width, size.height));
	}

	public void preview(Dimension size) {
		gen.render(size.width, size.height, 100000, 5);
	}

	@Override
	public void display(Image i) {
		this.image = i;
		this.repaint();
	}

	public void cancel() {
		this.gen.cancel();
	}

}
